package com.shell.scheduler.executor.chainbill;

import java.util.GregorianCalendar;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.base.utils.SystemUtil;
import com.shell.feign.PubParameterFeign;
import com.shell.framework.utils.SysDateUtil;
import com.shell.governor.modules.vo.ParameterVo;
import com.shell.scheduler.Executor;
import com.winchain.feign.BillExpirationExtFeign;

public class BillExpBatchJobExecutor implements Executor {
	private static final long serialVersionUID = -6452094645965943764L;
	protected final Log logger = LogFactory.getLog(getClass());
	@Autowired
	BillExpirationExtFeign billExpirationExtFeign;
	@Autowired
	private PubParameterFeign pubParameterFeign;

	public void execute(Map<String, String> context) {
		this.logger.info(getClass().getName() + " is executing...");
		String workDate = SysDateUtil.getSystemDate();
		if (!SystemUtil.SystemMode.prod.equals(SystemUtil.getSystemMode())) {
			ParameterVo parameter = this.pubParameterFeign.getCommonParameter("SYS_DATE_CONF");
			if ((parameter != null) && (!StringUtil.emptyAndNull(parameter.getParmValue()))) {
				workDate = parameter.getParmValue();
			}
		}
		this.billExpirationExtFeign.expire(workDate, isPm());
		this.logger.debug(getClass().getName() + " is execut successful...");
	}

	private boolean isPm() {
		GregorianCalendar ca = new GregorianCalendar();
		return ca.get(9) == 1;
	}
}